home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_vga.arc / VGA62-L3.ASM < prev    next >
Assembly Source File  |  1988-02-18  |  4KB  |  198 lines

  1. Code from "Yet Another VGA Write Mode" by Michael Abrash, PJ,
  2. Volume 6.2.  Copyright 1987 Michael Abrash 
  3. ;
  4. ; *** Listing 3 ***
  5. ;
  6. ; Program to illustrate flipping from bit-mapped graphics mode to
  7. ; text mode and back without losing any of the graphics bit-map.
  8. ;
  9. ; Assembled with MASM 5.0, linked with MS-LINK 3.60.
  10. ;
  11. ; By Michael Abrash 11/8/87
  12. ;
  13. Stack    segment    para stack 'STACK'
  14.     db    512 dup(0)
  15. Stack    ends
  16.  
  17. GRAPHICS_SEGMENT equ    0a000h    ;mode 10 bit-map segment
  18. TEXT_SEGMENT    equ    0b800h    ;mode 3 bit-map segment
  19. SC_INDEX    equ    3c4h    ;Sequence Controller Index register
  20. MAP_MASK    equ    2    ;index of Map Mask register
  21. GC_INDEX    equ    3ceh    ;Graphics Controller Index register
  22. READ_MAP    equ    4    ;index of Read Map register
  23.  
  24. Data    segment    para common 'DATA'
  25.  
  26. GStrikeAnyKeyMsg0    label    byte
  27.     db    0dh, 0ah, 'Graphics mode', 0dh, 0ah
  28.     db    'Strike any key to continue...', 0dh, 0ah, '$'
  29.  
  30. GStrikeAnyKeyMsg1    label    byte
  31.     db    0dh, 0ah, 'Graphics mode again', 0dh, 0ah
  32.     db    'Strike any key to continue...', 0dh, 0ah, '$'
  33.  
  34. TStrikeAnyKeyMsg    label    byte
  35.     db    0dh, 0ah, 'Text mode', 0dh, 0ah
  36.     db    'Strike any key to continue...', 0dh, 0ah, '$'
  37.  
  38. Plane2Save    db    2000h dup (?)    ;save area for plane 2 data
  39.                     ; where font gets loaded
  40. CharAttSave    db    4000 dup (?)    ;save area for memory wiped
  41.                     ; out by character/attribute
  42.                     ; data in text mode
  43. Data    ends
  44.  
  45. Code    segment    para public 'CODE'
  46.     assume    cs:Code, ds:Data
  47. Start    proc    near
  48.     mov    ax,10h
  49.     int    10h        ;select video mode 10h (640x350)
  50. ;
  51. ; Fill the graphics bit-map with a colored pattern.
  52. ;
  53.     cld
  54.     mov    ax,GRAPHICS_SEGMENT
  55.     mov    es,ax
  56.     mov    ah,3        ;initial fill pattern
  57.     mov    cx,4        ;four planes to fill
  58.     mov    dx,SC_INDEX
  59.     mov    al,MAP_MASK
  60.     out    dx,al        ;leave the SC Index pointing to the
  61.     inc    dx        ; Map Mask register
  62.  
  63. FillBitMap:
  64.     mov    al,10h
  65.     shr    al,cl        ;generate map mask for this plane
  66.     out    dx,al        ;set map mask for this plane
  67.     sub    di,di        ;start at offset 0
  68.     mov    al,ah        ;get the fill pattern
  69.     push    cx        ;preserve plane count
  70.     mov    cx,8000h    ;fill 32K words
  71.     rep stosw        ;do fill for this plane
  72.     pop    cx        ;get back plane count
  73.     shl    ah,1
  74.     shl    ah,1
  75.     loop    FillBitMap
  76. ;
  77. ; Put up "strike any key" message.
  78. ;
  79.     mov    ax,Data
  80.     mov    ds,ax
  81.     mov    dx,offset GStrikeAnyKeyMsg0
  82.     mov    ah,9
  83.     int    21h
  84. ;
  85. ; Wait for a key.
  86. ;
  87.     mov    ah,01h
  88.     int    21h
  89. ;
  90. ; Save the 8K of plane 2 that will be used by the font.
  91. ;
  92.     mov    dx,GC_INDEX
  93.     mov    al,READ_MAP
  94.     out    dx,al
  95.     inc    dx
  96.     mov    al,2
  97.     out    dx,al        ;set up to read from plane 2
  98.     mov    ax,Data
  99.     mov    es,ax
  100.     mov    ax,GRAPHICS_SEGMENT
  101.     mov    ds,ax
  102.     sub    si,si
  103.     mov    di,offset Plane2Save
  104.     mov    cx,2000h/2    ;save 8K (length of default font)
  105.     rep movsw
  106. ;
  107. ; Go to text mode without clearing display memory.
  108. ;
  109.     mov    ax,083h
  110.     int    10h
  111. ;
  112. ; Save the text mode bit-map.
  113. ;
  114.     mov    ax,Data
  115.     mov    es,ax
  116.     mov    ax,TEXT_SEGMENT
  117.     mov    ds,ax
  118.     sub    si,si
  119.     mov    di,offset CharAttSave
  120.     mov    cx,4000/2    ;length of one text screen in words
  121.     rep movsw
  122. ;
  123. ; Fill the text mode screen with dots and put up "strike any key"
  124. ; message.
  125. ;
  126.     mov    ax,TEXT_SEGMENT
  127.     mov    es,ax
  128.     sub    di,di
  129.     mov    al,'.'        ;fill character
  130.     mov    ah,7        ;fill attribute
  131.     mov    cx,4000/2    ;length of one text screen in words
  132.     rep stosw
  133.     mov    ax,Data
  134.     mov    ds,ax
  135.     mov    dx,offset TStrikeAnyKeyMsg
  136.     mov    ah,9
  137.     int    21h
  138. ;
  139. ; Wait for a key.
  140. ;
  141.     mov    ah,01h
  142.     int    21h
  143. ;
  144. ; Restore the text mode screen to the state it was in on entering
  145. ; text mode.
  146. ;
  147.     mov    ax,Data
  148.     mov    ds,ax
  149.     mov    ax,TEXT_SEGMENT
  150.     mov    es,ax
  151.     mov    si,offset CharAttSave
  152.     sub    di,di
  153.     mov    cx,4000/2    ;length of one text screen in words
  154.     rep movsw
  155. ;
  156. ; Return to mode 10h without clearing display memory.
  157. ;
  158.     mov    ax,90h
  159.     int    10h
  160. ;
  161. ; Restore the portion of plane 2 that was wiped out by the font.
  162. ;
  163.     mov    dx,SC_INDEX
  164.     mov    al,MAP_MASK
  165.     out    dx,al
  166.     inc    dx
  167.     mov    al,4
  168.     out    dx,al        ;set up to write to plane 2
  169.     mov    ax,Data
  170.     mov    ds,ax
  171.     mov    ax,GRAPHICS_SEGMENT
  172.     mov    es,ax
  173.     mov    si,offset Plane2Save
  174.     sub    di,di
  175.     mov    cx,2000h/2    ;restore 8K (length of default font)
  176.     rep movsw
  177. ;
  178. ; Put up "strike any key" message.
  179. ;
  180.     mov    ax,Data
  181.     mov    ds,ax
  182.     mov    dx,offset GStrikeAnyKeyMsg1
  183.     mov    ah,9
  184.     int    21h
  185. ;
  186. ; Wait for a key before returning to text mode and ending.
  187. ;
  188.     mov    ah,01h
  189.     int    21h
  190.     mov    ax,03h
  191.     int    10h
  192.     mov    ah,4ch
  193.     int    21h
  194. Start    endp
  195. Code    ends
  196.     end    Start
  197.  
  198.